#ifndef  MSGD_CORE_H
#define  MSGD_CORE_H 1

typedef struct msgd_listening_s  msgd_listening_t;
typedef struct msgd_event_s      msgd_event_t;
typedef struct msgd_connection_s msgd_connection_t;
typedef struct msgd_global_s     msgd_global_t;

typedef void (*msgd_event_handler_pt)(msgd_event_t *ev);
typedef void (*msgd_connection_handler_pt)(msgd_connection_t *c);

#define LIB_HANDLER void *
#define FREE_LIBRARY(libHandler) dlclose((libHandler))
#define LOAD_LIBRARY(file,flags) dlopen((file), (flags))
#define LOAD_LIBRARY_FLAGS RTLD_NOW | RTLD_LOCAL
#define OPEN_LIBRARY_ERROR dlerror()
#define GET_PROC_ADDRESS(libHandler, procName) dlsym((libHandler), (procName))


#define msgd_abs(value)       (((value) >= 0) ? (value) : - (value))
#define msgd_max(val1, val2)  ((val1 < val2) ? (val2) : (val1))
#define msgd_min(val1, val2)  ((val1 > val2) ? (val2) : (val1))

#define LIB_FILE_NAME_FORMAT "libmsgd_protocol_%s.so"
#define LIB_INIT_CONNECTION_FUN "msgd_init_connection"



#include <block_queue.h>
#include <mem_pool.h>
#include <msgd_global.h>
#include <logger.h>
#include <thread_pool.h>
#include <msgd_connection.h>
#include <str.h>
#include <fileutil.h>
#include <process/msgd_process.h>
#include <process/set_process_title.h>
#include <os/unix/atomic.h>
#include <os/unix/msgd_shmem.h>
#include <os/unix/msgd_channel.h>
#include <os/unix/msgd_thread.h>
#include <msgd_shmtx.h>
#include <msgd_rbtree.h>
#include <event/msgd_event.h>
#include <event/epoll_event.h>
#include <event/msgd_event_timer.h>

#include <xhead/msgd_xhead.h>



#define MSGD_OK     0
#define MSGD_ERROR -1
#define MSGD_AGAIN -2

#define MSGD_W 0200
#define MSGD_R 0400

#define FILE_MODE    (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 
#define MSGD_MODE    (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 


pid_t msgd_pid;

msgd_uint_t msgd_ncpu;

extern msgd_global_t global;

#endif // MSGD_CORE_H
